#include using namespace std; // 14, 112, 896, 146, 292, 584, 546, 168 void displayGameboard(int xMoves, int oMoves) { int i = 1; for (int r = 0; r < 3; r++) { for (int c = 0; c < 3; c++) { //we should display X if x has moved here // or O if O has moved here // you will need to use the bit if ((xMoves & _Pow_int(2, i)) == _Pow_int(2, i)) { cout << "X"; } else if ((oMoves & _Pow_int(2, i)) == _Pow_int(2, i)) { cout << "O"; } else { cout << i; } if (c < 2) { cout << "|"; } i++; } if (r < 2) { cout << endl << "-----" << endl; } } } int getValidMove(int xMoves, int oMoves) { int move; cin >> move; return move; } bool playerWon(int moves) { bool result = false; // 14, 112, 896, 146, 292, 584, 546, 168 return result; } bool catWon(int xMoves, int oMoves) { bool result = false; if (xMoves + oMoves == 1022) { result = true; } return result; } void main() { int xMoves = 0; int oMoves = 0; char turn = 'X'; bool gameOver = false; int move; while (!gameOver) //true will be replaced with a check to see if the game is over { //display the game board displayGameboard(xMoves, oMoves); //show whose turn it is cout << endl << turn << "'s turn" << endl; //ask for input for a move. Make sure it is valid. //cin >> move; move = getValidMove(xMoves, oMoves); //apply the move to xMoves or oMoves if (turn == 'X') { xMoves = (xMoves | _Pow_int(2, move)); //xMoves = xMoves + _Pow_int(2, move); turn = 'O'; } else { oMoves = (oMoves | _Pow_int(2, move)); turn = 'X'; } //check for a win if (playerWon(xMoves)) { cout << "X wins" << endl; gameOver = true; } if (playerWon(oMoves)) { cout << "O wins" << endl; gameOver = true; } if (catWon(xMoves, oMoves)) { cout << "CAT wins" << endl; gameOver = true; } } }